package com.likou.arr;

/**
 * Created by HXT on 2019/7/26.
 * 无重复字符的最长子串
 */
public class Solution {

    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.length() == 0) return 0;
        char[] chs = s.toCharArray();
        int[] freq = new int[128];//ascii表的最大表述范围
        int L = 0, R = -1;//L坐标 R右标
        int result = 0;
        while (R < s.length()) {
            if (R == s.length() - 1)
                break;
            if (freq[chs[R + 1]] == 0)
                freq[chs[++R]]++;
            else
                freq[chs[L++]]--;
            result = Math.max(result, R - L + 1);
        }
        return result;
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        System.out.println(solution.lengthOfLongestSubstring("abcabcbb"));
    }
}
